package com.ponhu.ea2.stockcenter.provider.config;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class Swagger3Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("oms XXX接口文档")
                .description("XXX")
                .contact(new Contact("lk", "", ""))
                .version("1.0.0-SNAPSHOT")
                .build();
    }

    @RestController
    @Api(value = "desc of class")
    public static class SwaggerTestController {

        @ApiOperation(value = "desc of method", notes = "")
        @RequestMapping("/hello")
        public String hello() {
            return "Hello Spring Boot!";
        }


        @ApiOperation(value = "hello one", notes = "")
        @GetMapping(value = "/hello1")
        public Object hello( /* 参数注解 */ @ApiParam(value = "desc of param", required = true) @RequestParam String name) {
            return "Hello " + name + "!";
        }


    }
}
